package threshold;


import java.util.ArrayList;
import java.util.List;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {}
    TreeNode(int val) {
        this.val = val;
    }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

/**
 * @Author wujiaming
 * @Description TODO
 * @Date 2023-03-06 16:33
 * @Version 1.0
 */
public class InorderTraversal {

    void inOrder(TreeNode root,List<Integer> list){
        if(root==null){return ;}
        inOrder(root.left,list);
        list.add(root.val);
        inOrder(root.right,list);
    }

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        inOrder(root,list);
        return list;
    }

    public static void main(String[] args) {
        InorderTraversal test = new InorderTraversal();
        TreeNode root = new TreeNode(1);
        TreeNode node1 = new TreeNode(2);
        TreeNode node2 = new TreeNode(3);
        root.left=null;root.right=node1;node1.left=node2;node1.right=null;
        List<Integer> integers = test.inorderTraversal(root);
        for (Integer integer:integers
             ) {
            System.out.println(integer);
        }
    }

}


